﻿@using mscook.mvc;
@{
    ViewBag.Title = "览月齐鲁";
    Layout = "~/Views/Shared/_CenterLayout.cshtml";
}
@model mscook.mvc.Models.CenterPresentModel

@section JavaScript
{
    <script type="text/javascript" src="@Url.Content("~/scripts/jquery.validate.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/scripts/jquery.validate.unobtrusive.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/scripts/jquery.unobtrusive-ajax.js")"></script>
    <script type="text/javascript">
        $("a.buyPresetn").click(function () {
            var resourceId = $(this).data("id");
            $("#makesurePresent").attr("data-id", resourceId);
            $("#BuyPrsentModal p.message").html("");
            $("#BuyPrsentModal").modal("show");
            return false;
        });

        $("#makesurePresent").click(function () {
            var url = $(this).data("url");
            var amount = $("#Amount").val();
            var address = $("#Address").val();
            var tel = $("#Tel").val();
            var id = $(this).attr("data-id");
            if (amount != "" && amount != null) {
                $.ajax({
                    url: url,
                    data: { amount: amount, address: address, tel: tel, id: id },
                    type: "POST",
                    dataType: "json",
                    success: function (data) {
                        $("#BuyPrsentModal p.message").html(data.Message);
                    }

                });
            }
        });


    </script>
}
<div class="modal hide fade" id="BuyPrsentModal">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">×</button>
        <h3>积分兑换礼品</h3>
    </div>
    <form>
        <div class="modal-body">

            <p>请输入数量兑换: @Html.TextBoxFor(o => o.Amount, new { value = "1" })</p>
            <p>@Html.ValidationMessageFor(o => o.Amount)</p>
            <p>请输入邮寄地址: @Html.TextBoxFor(o => o.Address)</p>
            <p>@Html.ValidationMessageFor(o => o.Address)</p>
            <p>请输入联系电话: @Html.TextBoxFor(o => o.Tel)</p>
            <p>@Html.ValidationMessageFor(o => o.Tel)</p>

            <input type="hidden" id="resourceId" />
            <p class="message"></p>
        </div>

        <div class="modal-footer">
            <a href="#" class="btn" data-dismiss="modal">关闭</a>
            <a href="javaScript:void(0)" id="makesurePresent" data-url="@Url.Action("BuyPresent")" class="btn btn-inverse">确定</a>

        </div>
    </form>

</div>
<div class="span9 main">
    <div class="row">
        <div class="span8 business_card highlight clearfix">
            <div class="card_header">
                <span class="card_title">
                    <i class=" icon-list-alt"></i>
                    <a target="_blank" href="#">积分礼品 <i class="chevron-right">›</i></a>
                </span>
            </div>
            <hr />
            @for (int i = 0; i < Model.PresentLit.Count; i++)
            {
                var item = Model.PresentLit.ElementAt(i);
                <div class="span2 items">
                    <div class="img">

                        <img src="@Html.Encode(Url.Content("~/Upload/wide/" + item.ImageName))">
                    </div>
                    <div class="info2">
                    </div>
                    <div class="mag_info1">
                        <div class="mag_in_til">
                            <h4>
                                <a href="#">@Html.Encode(item.Name)</a>
                            </h4>
                            <p>
                                <span>所需积分：</span>
                                <span>@Html.Encode(item.AbsBonus)</span>
                            </p>
                        </div>
                        @if (Model.LoginUser.Bonus < item.AbsBonus)
                        {
                             <a href="@Url.Action("BonusBuy")" class="btn">积分不足请充值</a>
                        }
                        else
                        {
                            <a href="#" data-id="@item.Id" class="buyPresetn btn">积分兑换</a>
                        }
                    </div>
                </div>
            }


        </div>
    </div>
</div>
